package tokens;

import java.util.ListIterator;
import java.util.Queue;
import java.util.Stack;

import parser.ParserException;
import nodes.AbstractNode;
import nodes.binary.MultiplyNode;

/**
 * Multiplication token
 * 
 * @author Charlie Hatcher
 * @author Roman
 */
public class MultiplyToken extends AbstractBinaryToken {
	private static final String MULTIPLY_TOKEN = "\\*";

	public MultiplyToken() {
		precedence = 1;
	}

	@Override
	public AbstractNode process() {

		return new MultiplyNode(myModel);
	}

	@Override
	public boolean matchToken(String str, ListIterator<String> it) {

		return str.matches(MULTIPLY_TOKEN);
	}

	@Override
	public void handleParser(String str, ListIterator<String> it,
			Stack<AbstractBinaryToken> opStack,
			Queue<AbstractNode> outPutQueue, Queue<AbstractNode> queue)
			throws Exception {
		if (!outPutQueue.isEmpty()) {
			AbstractNode temp = outPutQueue.poll();
			outPutQueue.add(new MultiplyToken().process());
			outPutQueue.add(temp);
		} else
			throw ParserException.BAD_SYNTAX;

	}

}